package ink.lovejinhu.swardToOffer;

import java.util.Stack;

/**
 * @author jinhu
 * created 2021-08-08 14:08
 */
public class Offer_030 {
    /**
     * 单调栈设计
     */
    Stack<Integer> v0 = new Stack<>();
    Stack<Integer> v1 = new Stack<>();

    /**
     * initialize your data structure here.
     */
    public Offer_030() {

    }

    public void push(int x) {
        v0.push(x);
        if (v1.isEmpty()) {
            v1.push(x);
        } else {
            if (x <= v1.peek()) {
                v1.push(x);
            }
        }
    }

    public void pop() {
        if (v0.peek().equals(v1.peek())) {
            v0.pop();
            v1.pop();
        } else {
            v0.pop();
        }
    }

    public int top() {
        return v0.peek();
    }

    public int min() {
        return v1.peek();
    }
}
